package com.glsc.ngateway.platform.service.itflow.flowstrategy.equipmentServerApply.taskPostHandler;

import com.alibaba.fastjson.JSONObject;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.equipment.EquipmentPassParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.equipment.EquipmentRejectParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.equipment.EquipmentServerApplyTaskFormDataDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.equipment.domainDto.FlowFormEquipmentServerApplyDto;
import com.glsc.ngateway.common.api.flowable.dto.task.message.EquipmentFlowMessageDto;
import com.glsc.ngateway.platform.service.itflow.flowstrategy.IItFlowMQHandler;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowTaskEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;

/**
 * 网络管理员复核
 * @author xuchang
 */
@Component
public class ESAStep8NetAdminReviewTaskPostHandlerAudit implements IEquipmentServerApplyTaskPostHandlerAudit, IItFlowMQHandler {

    @Autowired
    private ESAStepHandlerHelper handlerHelper;

    /**
     * 驳回后置处理方法
     * @param passParam
     * @param operator
     */
    @Override
    public void rejectAfterHandle(@NotNull EquipmentRejectParamDto passParam, @NotNull String operator) {
        handlerHelper.afterHandle(passParam, operator);
    }

    @Override
    public void passAfterHandle(@NotNull EquipmentPassParamDto<FlowFormEquipmentServerApplyDto, EquipmentServerApplyTaskFormDataDto> param, String operator) {
        handlerHelper.endTaskAfterHandle(param, operator, this.getMqCodeKey());
    }

    @Override
    public void doHandle(String msg) {
        EquipmentFlowMessageDto msgJsonObject = JSONObject.parseObject(msg, EquipmentFlowMessageDto.class);
        handlerHelper.applyServerEquipment(msgJsonObject.getMainFormId());
    }

    @Override
    public String getTaskDefinitionKey() {
        return ITFlowTaskEnum.SERVER_APPLY_FLOW_NET_ADMIN_REVIEW_TASK.getTaskKey();
    }

    @Override
    public String getMqCodeKey() {
        return ITFlowTaskEnum.SERVER_APPLY_FLOW_NET_ADMIN_REVIEW_TASK.getMqCodeKey();
    }
}
